#include "InetAddr.hpp"
#include "Log.hpp"
#include <functional>
#include <memory>
#include <string>
#include "UdpServer.hpp"
#include "Route.hpp"
#include "ThreadPool.hpp"
using namespace LogModule;
using namespace ThreadModule;
using task_t = std::function<void()>;
int main(int argc, char* argv[]) {
    if(argc != 2) {
        cout << "The usage is " << argv[0] << "+port" << endl;
        return 1;
    }
    uint16_t port = std::stoi(argv[1]);
    EnableConsoleLogStrategy();
    Route route;
    auto tp = ThreadPool<task_t>::GetInstance();
    std::unique_ptr<UdpServer> udp = std::make_unique<UdpServer>(port, [&route, &tp](int sockfd, const std::string message, InetAddr& addr) {
        task_t t = std::bind(&Route::messageRoute, &route, sockfd, message, addr);
        tp->Enqueue(t);
    });
    udp->Init();
    udp->Start();
    return 0;
}